package com.lrkj.back;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lrkj.back.entity.*;
import com.lrkj.back.service.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Bean;

public class StartUpOnLoadData{
	
	public static final String MIEJUN_KEY ="NAVGRFKM_MJFS" ;
	
	public static final String QXFL = "VOTTQXPT_QXFL";
	
	public static final String MIEJUN_WLSX = "BDMFPHAY_WLSX";

	public static final String WPFL = "OUXSGKZI_WPFL";
	
	public static Map<String,List<TbDict>> dataListMap = new HashMap<>();
	
	public static Map<Long,TbDict> singleDataMap = new HashMap<>();
	
	public static Map<Long,ZsEquip> equipMap = new HashMap<>();

	public static Map<Long,ZsSoft> softMap = new HashMap<>();

	public static Map<Long,String> equipSinMap = new HashMap<>();

	public static Map<Long,String> softSinMap = new HashMap<>();

	public static Map<String,String> emMap = new HashMap<>();

	public static Map<String,String> wanglanMap = new HashMap<>();

	public static Map<String,String> depMap = new HashMap<>();

	public static Map<Integer,String> sendMap = new HashMap<>();

	@Autowired
	private TbDictService dictService;
	@Autowired
	private ZsEquipService equipService;
	@Autowired
	private ZsSoftService softService;
	@Autowired
	private TbEmployeeService empService;

	@Autowired
	private ZsWanglanService zsWanglanService;

	@Autowired
	private TbDepartmentService tbDepartmentService;

	@Autowired
	private SendImservice sendImservice;
	
	private Logger log = Logger.getLogger(StartUpOnLoadData.class);
    /** 
     * Spring 容器初始化时加载 
     */  
    public void loadData() {  
    	loadDictData();
    	loadEquipData();
    	loadSoftData();
    	loadEmpData();
		loadwlData();
		loaddepData();
		loadEquipSinData();
		loadSoftSinData();
		loadsendData();
    }
    
    private void loadEmpData() {
    	log.error("start load emp data.....");
    	List<TbEmployee> empList= empService.queryEmployeeList(new HashMap<String,Object>());
    	for(TbEmployee emp : empList){
    		emMap.put(emp.getEmployeeNo(), emp.getEmployeeName());
    	}
    	log.error("end load emp data....."); 
	}

	private void loadSoftData() {
		log.error("start load soft data.....");
    	List<ZsSoft> softList= softService.queryZsSoftList(new HashMap<String,Object>());
    	for(ZsSoft soft : softList){
    		softMap.put(Long.valueOf(soft.getSoftId()), soft);
    	}
    	log.error("end load soft data....."); 
	}

	private void loadEquipData() {
		log.error("start load equip data.....");
    	List<ZsEquip> equipList= equipService.findAllZsEquipListNoPage(new HashMap<String,Object>());
    	for(ZsEquip equip : equipList){
    		equipMap.put(Long.valueOf(equip.getEquipId()), equip);
    	}
    	log.error("end load equip data.....");
	}

	private void loadsendData() {
		log.error("start load send data.....");
		List<SendIm> sendImList= sendImservice.findAll(new HashMap<String,Object>());
		for(SendIm sendIm : sendImList){
			sendMap.put(sendIm.getSendId(), sendIm.getSendName());
		}
		log.error("end load send data.....");
	}

	private void loadSoftSinData() {
		log.error("start load soft data.....");
		List<ZsSoft> softList= softService.queryZsSoftList(new HashMap<String,Object>());
		for(ZsSoft soft : softList){
			softSinMap.put(Long.valueOf(soft.getSoftId()), soft.getSoftName());
		}
		log.error("end load soft data.....");
	}

	private void loadEquipSinData() {
		log.error("start load equip data.....");
		List<ZsEquip> equipList= equipService.findAllZsEquipListNoPage(new HashMap<String,Object>());
		for(ZsEquip equip : equipList){
			equipSinMap.put(Long.valueOf(equip.getEquipId()), equip.getEquipName());
		}
		log.error("end load equip data.....");
	}

	private void loadwlData() {
		log.error("start load wl data.....");
		List<ZsWanglan> wanglanList= zsWanglanService.findWanglanListByNoPage(new HashMap<String,Object>());
		for(ZsWanglan wanglan : wanglanList){
			wanglanMap.put(wanglan.getWlTiaoma(), wanglan.getWlMingcheng());
		}
		log.error("end load wl data.....");
	}

	private void loaddepData() {
		log.error("start load dep data.....");
		List<TbDepartment> departmentList= tbDepartmentService.findAllDepartment();
		for(TbDepartment tbDepartment : departmentList){
			depMap.put(tbDepartment.getDepartmentId(), tbDepartment.getDepartmentName());
		}
		log.error("end load wl data.....");
	}

	private void loadDictData(){
		log.error("start load dict data.....");
    	List<TbDict> dataList= dictService.findDictList();
    	for(TbDict dict : dataList){
    		singleDataMap.put(Long.valueOf(dict.getDictId()), dict);
    		if(dict.getDictParentid() == null){
    			List<TbDict> dictList = dictService.findDetailByCode(dict.getDictCode());
    			dataListMap.put(dict.getDictCode(), dictList);  
    		}
    	}
    	log.error("end load dict data.....");
    }
	  
}
